package com.cn.ccp.util;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 

public class StringConverter implements Converter {
	private Log log = LogFactory.getLog(StringConverter.class);

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			   String newValues) {
		String newstr = "";
		  if (newValues == null) {
		   newValues = "";
		  }
		  try {
		   newstr = StringEscapeUtils.unescapeHtml(newValues);
		   log.info("------------"+newstr);
		   UIInput input=(UIInput)component;//
		   input.setSubmittedValue(newstr);
		  } catch (Exception e) {
			  log.error("format code failed : ", e);
		  }

		  return newstr;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		return (String) arg2;
	}

}
